package config

import "fmt"

type Config struct {
	System   System   `mapstructure:"system" json:"system" yaml:"system"`
	Static   Static   `mapstructure:"static" json:"static" yaml:"static"`
	StaticFS StaticFS `mapstructure:"static-fs" json:"static-fs" yaml:"static-fs"`
	Zap      Zap      `mapstructure:"zap" json:"zap" yaml:"zap"`
	Mysql    Mysql    `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
	Redis    Redis    `mapstructure:"redis" json:"redis" yaml:"redis"`
	MinIO    MinIO    `mapstructure:"minio" json:"minio" yaml:"minio"`
	Captcha  Captcha  `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
	JWT      JWT      `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
	// Qiniu      Qiniu      `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
	// AliyunOSS  AliyunOSS  `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
	// TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
	// Excel      Excel      `mapstructure:"excel" json:"excel" yaml:"excel"`
}

type System struct {
	Port               int    `mapstructure:"port" json:"port" yaml:"port"`
	Host               string `mapstructure:"host" json:"host" yaml:"host"`
	DBType             string `mapstructure:"db-type" json:"db-type" yaml:"db-type"`
	OSSType            string `mapstructure:"oss-type" json:"oss-type" yaml:"oss-type"`
	UseMultipoint      bool   `mapstructure:"use-multipoint" json:"use-multipoint" yaml:"use-multipoint"`
	MaxMultipartMemory int64  `mapstructure:"max-multipart-memory" json:"max-multipart-memory" yaml:"max-multipart-memory"`
	Salt               string `mapstructure:"salt" json:"salt" yaml:"salt"`
}

type Static struct {
	RelativePath string `mapstructure:"relative-path" json:"relative-path" yaml:"relative-path"`
	Root         string `mapstructure:"root" json:"root" yaml:"root"`
}

type StaticFS struct {
	RelativePath string `mapstructure:"relative-path" json:"relative-path" yaml:"relative-path"`
	FS           string `mapstructure:"fs" json:"fs" yaml:"fs"`
}

type Mysql struct {
	Host         string `mapstructure:"host" json:"host" yaml:"host"`
	Port         int    `mapstructure:"port" json:"port" yaml:"port"`
	Username     string `mapstructure:"username" json:"username" yaml:"username"`
	Password     string `mapstructure:"password" json:"password" yaml:"password"`
	DBName       string `mapstructure:"db-name" json:"db-name" yaml:"db-name"`
	Config       string `mapstructure:"config" json:"config" yaml:"config"`
	MaxIdleConns int    `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"`
	MaxOpenConns int    `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"`
}

func (m *Mysql) Dsn() string {
	return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s", m.Username, m.Password, m.Host, m.Port, m.DBName, m.Config)
}

type Redis struct {
	Enable   bool   `mapstructure:"enable" json:"enable" yaml:"enable"`
	DB       int    `mapstructure:"db" json:"db" yaml:"db"`
	Host     string `mapstructure:"host" json:"host" yaml:"host"`
	Port     int    `mapstructure:"port" json:"port" yaml:"port"`
	Password string `mapstructure:"password" json:"password" yaml:"password"`
}

type MinIO struct {
	Enable          bool   `mapstructure:"enable" json:"enable" yaml:"enable"`
	Endpoint        string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
	DeployHost      string `mapstructure:"deploy-host" json:"deploy-host" yaml:"deploy-host"`
	DeployPort      int    `mapstructure:"deploy-port" json:"deploy-port" yaml:"deploy-port"`
	AccessKeyID     string `mapstructure:"access-key-id" json:"access-key-id" yaml:"access-key-id"`
	SecretAccessKey string `mapstructure:"secret-access-key" json:"secret-access-key" yaml:"secret-access-key"`
	Secure          bool   `mapstructure:"secure" json:"secure" yaml:"secure"`
}

type Captcha struct {
	Length    int `mapstructure:"length" json:"length" yaml:"length"`
	ImgWidth  int `mapstructure:"img-width" json:"img-width" yaml:"img-width"`
	ImgHeight int `mapstructure:"img-height" json:"img-height" yaml:"img-height"`
}

type Zap struct {
	LogPath string `mapstructure:"log-path" json:"log-path" yaml:"log-path"`
}

type JWT struct {
	SigningKey  string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"`
	ExpiresTime int    `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"`
	Issuer      string `mapstructure:"issuer" json:"issuer" yaml:"issuer"`
}
